package com.stoneapple.timesheet.Servlet;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

import com.stoneapple.timesheet.dao.TSDao;


@SuppressWarnings("serial")
public class DeleteTimesheetServlet  extends HttpServlet{
private static final Logger log=Logger.getLogger(CreateTimesheetServlet.class.getName());
	
	public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException{
		
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();
		
		if (user == null) {
			String loginUrl = userService.createLoginURL(req.getRequestURI());
			resp.sendRedirect(loginUrl);

		} else {

	String timesheetID = req.getParameter("id");
			
			TSDao timesheet = TSDao.getInstance();
			timesheet.delete(Long.parseLong(timesheetID));
			
			log.info("Delete  Id: " + timesheetID);
			
			resp.sendRedirect("/timesheet");		
			
		}}
}